package edu.mis.model;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import edu.mis.model.base.BaseGoods;


@SuppressWarnings("serial")
public class Goods extends BaseGoods<Goods> {
	public static final Goods dao = new Goods().dao();
	
	public List<Record> findAllRecord(){
		return Db.find("SELECT g.*,c.categoryName FROM goods g LEFT JOIN category c ON g.categoryId=c.id" );
	}
	
	
	public List<Goods> findAll(){
		return dao.find("SELECT * FROM goods");
	}
	
	public Goods findGoodsByName(String name){
		return findFirst("SELECT * FROM goods WHERE name = ? ",name);
	}
	
	
	public Category getCategory(){
		return Category.dao.findById(get("categoryId"));
	}
}
